package com.shou.domain.park.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shou.domain.common.AbstractService;
import com.shou.domain.common.PageQueryEntity;
import com.shou.domain.park.model.ParkingRecordEntity;
import com.shou.domain.park.repository.IParkingRecordRepository;
import com.shou.domain.park.service.IParkingRecordService;
import com.shou.types.common.TableNameEnum;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Nemo
* @description 针对表【parkingrecords(停车记录表，记录车辆的进出信息)】的数据库操作Service实现
* @createDate 2025-02-07 22:10:51
*/
@Service
public class ParkingRecordService extends AbstractService implements IParkingRecordService {
    @Resource
    private IParkingRecordRepository parkingRecordRepository;
    @Override
    public void insertParkingRecord(ParkingRecordEntity parkingRecordEntity) {
        validateParkingRecordEntity(parkingRecordEntity);
        parkingRecordRepository.insert(parkingRecordEntity);
    }

    @Override
    public ParkingRecordEntity getParkingRecordById(Integer id) {
        return parkingRecordRepository.getParkingRecordById(id);
    }

    @Override
    public IPage<ParkingRecordEntity> pageQuery(PageQueryEntity pageQueryEntity) {
        pageQueryEntity.setSortName(camelToSnake(pageQueryEntity.getSortName()));
        validateQueryParams(pageQueryEntity, TableNameEnum.PARKING_RECORD);
        return parkingRecordRepository.getParkingRecordsPage(pageQueryEntity);
    }

    @Override
    public void updateParkingRecordById(ParkingRecordEntity parkingRecordEntity) {
        Integer id = parkingRecordEntity.getId();
        if(id == null || !checkIfExistById(id, TableNameEnum.PARKING_RECORD)){
            throw new RuntimeException("id为" + id + "的记录不存在");
        }
        validateParkingRecordEntity(parkingRecordEntity, parkingRecordEntity.getId());
        parkingRecordRepository.updateParkingRecordById(parkingRecordEntity);
    }

    @Override
    public void deleteByIds(List<Integer> ids) {
        super.deleteByIds(ids, TableNameEnum.PARKING_RECORD);
    }

    @Override
    public void deleteAll() {
        super.deleteAll(TableNameEnum.PARKING_RECORD);
    }

    private void validateParkingRecordEntity(ParkingRecordEntity parkingRecord, Integer... excludeIds) {
    }
}




